
import DialogBox from './DialogBox'
import router from "@/router"
import FormCustomView from "@/views/modules/form/core/formComponent/FormCustomView";
import {Util,TabOpen} from "@lowcode/jpaas-common-lib";
import DialogView from "@/layouts/DialogView";

export default {
    //增加在TAB中打开新页面
    mixins:[TabOpen],
    methods:{
        /**
         * 打开打开表单
         * @param conf
         * {
         *     title:"",
         *     alias:"",
         *     pkId:"",
         *     readOnly:true,
         *     data:{},
         *     max:true,
         *     widthHeight:['600px','400px']
         * }
         * @param callback
         * function(action,data){
         *
         * }
         * @returns {{}|*}
         */
        openFormSolution(conf,callback){
            let config={
                title:conf.title,
                curVm: this,
                max:conf.max,
                widthHeight:conf.widthHeight,
                data: {
                        alias: conf.alias,
                        pkId: conf.pkId,
                        readOnly: conf.readOnly,
                        setInitData(data){
                            if(conf.data){
                                return conf.data;
                            }
                            return {};
                        }
                },

            }
            DialogBox.showForm(config, function (action,data) {
                if(callback){
                    callback(action,data);
                }
            });
        },
        /**
         * 打开表单
         * @param conf
         * {
         *     formAlias:"",
         *     pkId:""
         * }
         */
        openFormUrl(conf){
            router.push({name:"customform",params:conf})
        },
        /**
         * 使用window.open打开新窗口
         * @param conf
         * {
         *     formAlias:"表单方案Id",
         *     pkId:"",
         *     readOnly:使用只读的方式打开
         * }
         */
        openWindowUrl(conf){
            let json={
                params:conf
            }
            if(conf.readOnly){
                json.name='customFormRead';
            }
            else{
                json.name='customform';
            }
            let obj=this.$router.resolve(json);
            window.open(obj.href,"_blank" );
        },

        /**
         * 打开列表。
         * @param alias
         */
        openList(alias){
            let obj=this.$router.resolve({
                name:'formBoList',
                params:{listKey:alias},
            });
            window.open(obj.href,"_blank" );
        },
        /**
         * 打开列表对话框。
         * @param key:"对话框KEY"
         * @param single:是否单选
         * @param params:"Q_NAME__S_EQ=老王"
         * @param config  {title:'',max:true,widthHeight:[]}
         * @param callback
         */
        openListDialog(key,single,params,config,callback){
            DialogBox.dialog({
                key:key,
                params:params || "",
                single:config.single || false
            },{
                title:config.title,
                curVm: this,
                widthHeight:config.widthHeight,
                max:config.max
            }, function (action,data) {
                if(callback){
                    callback(action,data);
                }
            });
        },
        /**
         * 打开页面定制
         * @param alias 别名
         * @param params 传入参数
         * @param title 对话框名称
         * @param callback 回调函数
         */
        openCustomView(alias,params,title,config,callBack){
            title=title || "表单定制-"+alias;
            let self_=this;
            let ctxPath= process.env.VUE_APP_CONTEXT_MAIN;
            let url=`${ctxPath}/FormCustomView/${alias}?appId=${config.appId}`;
            var baseConf= {
                "curVm": self_,
                //FormCustomView
                component: DialogView,
                title: title,
                max: config.max,
                widthHeight: [config.width+"px", config.height+"px"],
                shade:config.shade,
                data: {
                    dialogBox:callBack,
                    url:url
                }
                // "data": {
                //     "alias": alias,
                //     "params": JSON.stringify(params)
                // }
            };
            Util.open(baseConf, function (action,data) {
                if(!callBack){
                    return;
                }
                callBack(action,data);
            });
        },


    }
}